import request from './axios'
import * as tokenTools from '@/utils/tokenTools.js'

export function addPost(content, type, user_ids, image_url, video_url) {
    return request({
        url: '/article/add',
        method: 'post',
        data: {
            content,
            type,
            user_ids,
            image_url,
            video_url
        },
        headers: {
            token: tokenTools.getToken(),
            'Content-Type': 'application/json'
        }
    })
}

export function getPost(id) {
    return request({
        url: '/article/articleDetail',
        method: 'get',
        params: {
            id
        }
    }).then(res => res?.data?.data)
}


// type 类型：1.文章，2.评论
// id 类型1.表示文章ID，类型2表示评论id
// comments_type 评论类型：1.文章，2.图片，3.视频
// content 评论类型1.内容必传，评论类型2或3，可传可不传
// type: 1
// comments_type: 1
// content: sdsds
export function createComment(type, id, comments_type, content, image, video) {
    const data = {type, comments_type, content}
    if (image) {
        data.image = image
    }
    if (video) {
        data.video = video
    }
    return request({
        url: '/topic/replyReview',
        method: 'post',
        data
    })
}